package com.quanquan.parking.ketop.repository;

import com.quanquan.parking.ketop.entity.UserCarKetop;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:UserCarRepository
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/9/9 16:02
 * @Version 1.0
 */
public interface UserCarKetopRepository extends JpaRepository<UserCarKetop, String>, JpaSpecificationExecutor<UserCarKetop> {

    /**
     * 用户是否绑定某个车牌
     *
     * @param userId
     * @return
     */
    @Query(value = "select * from oo_user_car_ketop where user_id = ?1 and plate_num = ?2", nativeQuery = true)
    List<UserCarKetop> findByUserIdAndPlateNum(String userId, String plateNum);

    /**
     * 用户绑定车牌
     *
     * @param userId
     * @return
     */
    @Query(value = "select * from oo_user_car_ketop where status = 0 and user_id = ?1 order by update_time desc limit ?2,?3", nativeQuery = true)
    List<UserCarKetop> findByUserId(String userId, Integer count, Integer size);

}
